Shader "HolaShader/LambertVertexShader"
{
    //漫反射公式：f(θ) =（_even_light_color * _diffuse）max(LightDir•NormalDir,0)
    //环境光颜色*自定漫反射光颜色*max（dot(环境光方向，法线方向)， 0）
    Properties
    {
        _Diffuse("Diffuse Color", Color) = (1,1,1,1)
    }
    SubShader
    {
        Tags { "LightMode"="ForwardBase" }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            //为了使用Unity的一些内置变量，需要包含进Unity的内置文件“Lighting.cginc”
            #include "Lighting.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
            };

            struct v2f
            {
                float4 pos : SV_POSITION;
                fixed3 color : COLOR;
            };

            fixed4 _Diffuse;
            v2f vert (appdata v)
            {
                v2f o;
				o.pos = UnityObjectToClipPos(v.vertex);

				fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz;
				fixed3 worldNormal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal));
				fixed3 worldLight = normalize(_WorldSpaceLightPos0.xyz);
				fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * max(dot(worldNormal,worldLight),0);

				o.color = ambient + diffuse;
				return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                return fixed4(i.color.rgb, 1.0);
            }
            ENDCG
        }
    }
    Fallback "Diffuse"
}
